$(function() {
    var start = moment().subtract(29, 'days');
    var end = moment();
    var cgpstime = $('#cgpstime');
    var wdpstime = $('#wdpstime');
    var qxpstime = $('#qxpstime');
    var yypstime = $('#yypstime');
    var zztime   = $('#zztime');
    var jdtime   = $('#jdtime');
    var yctime   = $('#yctime');
    var sjtime   = $('#sjtime');
    var yyfptime = $('#yyfptime');
    var hsfptime = $('#hsfptime');
    var hsldtime = $('#hsldtime');
    var yysktime = $('#yysktime');
    var qxyytime = $('#qxyytime');
    var hsbmtime = $('#hsbmtime');
    var skcgtime = $('#skcgtime');
    var hskktime = $('#hskktime');
    var yycgtime = $('#yycgtime');
    var fktime = $('#fktime');
    chushi(cgpstime);
    chushi(wdpstime);
    chushi(qxpstime);
    chushi(yypstime);
    chushi(zztime);
    chushi(jdtime);
    chushi(yctime);
    chushi(sjtime);
    chushi(yyfptime);
    chushi(hsfptime);
    chushi(hsldtime);
    chushi(yysktime);
    chushi(qxyytime);
    chushi(hsbmtime);
    chushi(skcgtime);
    chushi(hskktime);
    chushi(yycgtime);
    chushi(fktime);

    function chushi(name) {
        if (name.val() == ''){
            datetime(name);
            name.val("");
        }else{
            name.on('focus',function () {
                datetime(name);
            });

        }
        name.on('cancel.daterangepicker',function(ev, picker) {
            name.val('');
        });
    }
    function datetime(name) {
        name.daterangepicker({
            language: 'zh-CN',                                      //这里需要修改
            startDate: start,
            endDate: end,
            // singleDatePicker:true,
            ranges: {
                '今天': [moment(), moment()],
                '昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                '本周': [moment().startOf('week').add(1,'days'),moment().endOf('week').add(1,'days')],
                '本月': [moment().startOf('month'), moment().endOf('month')],
                '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
                // '清除':  [qingchu(name)],
            },
            locale: {
                direction:"ltr",
                format: "YYYY-MM-DD",
                separator: "~",
                applyLabel: '确定',
                cancelLabel: '清除',
                fromLabel: '起始时间',
                toLabel: '结束时间',
                customRangeLabel: '自定义',
                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
                    '七月', '八月', '九月', '十月', '十一月', '十二月'],
                firstDay: 1
            }
        });
    }
});
